import java.util.Scanner;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * user:likai
 * Date:2022-12-18
 * Time:15:40
 */
 class Parenthesis {
    public boolean chkParenthesis(String A, int n) {
        // write code here
        if(n%2!=0){
            return false;
        }
        Stack<Character> stack=new Stack<>();
        for(int i=0;i<A.length();i++){
            if(A.charAt(i)=='('){
                stack.push(A.charAt(i));
            }else if(A.charAt(i)==')'){
                if(stack.isEmpty()){
                    return false;
                }else{
                    stack.pop();
                }
            }else{
                return false;
            }
        }
        return stack.isEmpty();
    }
}
public class Test {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int m=scanner.nextInt();
        int fit1=0;
        int fit2=1;
        while(m>fit2){
            int tmp=fit1+fit2;
            fit1=fit2;
            fit2=tmp;
        }
        int n=fit2-m<m-fit1?fit2-m:m-fit1;
        System.out.println(n);
    }
}
